package com.pureut.order.controller;

import com.pureut.common.core.domain.R;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.order.dto.ConverterManagementDto;
import com.pureut.order.dto.SampleManagementDto;
import com.pureut.order.service.SampleManagementService;
import com.pureut.order.vo.ConverterManagementVo;
import com.pureut.order.vo.OrderReviewVo;
import com.pureut.order.vo.SampleManagementVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 样品管理控制层
 */
@RestController
@RequestMapping("/sample-management")
public class SampleManagementController extends BaseController {


    @Resource
    SampleManagementService sampleManagementService;

    /**
     * 样品管理列表
     */
    @RequiresPermissions("order:sample:list")
    @GetMapping("/list")
    public TableDataInfo list(SampleManagementVo sampleManagementVo) {
        startPage();
        //查询样品管理列表
        List<SampleManagementDto> list = sampleManagementService.getList(sampleManagementVo);
        return getDataTable(list);
    }

    /**
     * 新增样品
     */
    @RequiresPermissions("order:sample:add")
    @Log(title = "新增样品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody SampleManagementVo sampleManagementVo) throws Exception {
        return toAjax(sampleManagementService.saveSample(sampleManagementVo));
    }

    /**
     * 修改
     */
    @RequiresPermissions("order:sample:edit")
    @Log(title = "修改样品", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@Validated @RequestBody SampleManagementVo sampleManagementVo) {
        return toAjax(sampleManagementService.updateSample(sampleManagementVo));
    }

    /**
     * 查看
     */
    @RequiresPermissions("order:sample:query")
    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") Long id) {
        return AjaxResult.success(sampleManagementService.getSampleById(id));
    }

    /**
     * 提交审核
     */
    @RequiresPermissions("order:sample:submitReview")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{id}")
    public AjaxResult submitReview(@PathVariable("id") Long id) {
        return toAjax(sampleManagementService.submitReview(id));
    }

    /**
     * 撤销审核
     */
    @RequiresPermissions("order:sample:deleteReview")
    @Log(title = "撤销审核", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{id}")
    public AjaxResult deleteReview(@PathVariable("id") Long id) {
        return toAjax(sampleManagementService.deleteReview(id));
    }

    /**
     * 删除样品
     */
    @RequiresPermissions("order:sample:remove")
    @Log(title = "删除样品", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable("ids") String ids){
        return toAjax(sampleManagementService.deleteSample(ids));
    }


    /**
     * 样品审核
     */
    @RequiresPermissions("order:sample:review")
    @Log(title = "样品审核", businessType = BusinessType.UPDATE)
    @PostMapping("/sampleReview")
    public AjaxResult sampleReview(@Validated @RequestBody OrderReviewVo orderReviewVo) throws Exception {
        return toAjax(sampleManagementService.sampleReview(orderReviewVo));
    }
}
